package com.ysxsoft.wdg.ui.activity.order;

import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.widget.TextView;
import com.ysxsoft.wdg.R;
import com.ysxsoft.wdg.adapter.FragmentAdapter;
import com.ysxsoft.wdg.base.BaseActivity;
import com.ysxsoft.wdg.base.BaseFragment;
import com.ysxsoft.wdg.ui.fragment.order.OrderMjFragment;
import com.ysxsoft.wdg.ui.fragment.order.OrderStFragment;
import com.ysxsoft.wdg.ui.fragment.order.OrderTbFragment;
import com.ysxsoft.wdg.ui.fragment.order.OrderZyFragment;
import com.ysxsoft.wdg.util.AlibcUtils;
import com.ysxsoft.wdg.widget.viewpager.NoScrollViewPager;
import java.util.ArrayList;
import java.util.List;
import butterknife.BindView;
import butterknife.OnClick;

public class OrderActivity extends BaseActivity {


    public static void start(Context context){
        Intent intent = new Intent(context,OrderActivity.class);
        context.startActivity(intent);
    }

    @BindView(R.id.topView)
    View topView;
    @BindView(R.id.title_content)
    TextView titleContent;
    @BindView(R.id.tv_zy)
    TextView tvZy;
    @BindView(R.id.tv_st)
    TextView tvSt;
    @BindView(R.id.tv_mj)
    TextView tvMj;
    @BindView(R.id.tv_tb)
    TextView tvTb;
    @BindView(R.id.viewPager)
    NoScrollViewPager viewPager;

    private FragmentAdapter adapter;
    private List<BaseFragment> fragments;

    private TextView[] textViews;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_order;
    }

    @Override
    protected void initData() {
        initStatusBar(topView,false);
        titleContent.setText("我的订单");

        textViews = new TextView[]{tvZy,tvSt,tvMj,tvTb};

        fragments = new ArrayList<>();
        fragments.add(new OrderZyFragment());
        fragments.add(new OrderStFragment());
        fragments.add(new OrderMjFragment());
        fragments.add(new OrderTbFragment());

        adapter = new FragmentAdapter(getSupportFragmentManager(),fragments);
        viewPager.setAdapter(adapter);

        viewPager.setOffscreenPageLimit(1);
        setSelector(0);
    }

    @Override
    protected void setListener() {

    }


    @OnClick({R.id.title_finish, R.id.tv_zy, R.id.tv_st,
            R.id.tv_mj, R.id.tv_tb})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.title_finish:
                finish();
                break;
            case R.id.tv_zy:
                setSelector(0);
                break;
            case R.id.tv_st:
                setSelector(1);
                break;
            case R.id.tv_mj:
                setSelector(2);
                break;
            case R.id.tv_tb:
//                setSelector(3);
                AlibcUtils.showOrder(OrderActivity.this);//显示淘宝订单
                break;
        }
    }


    public void setSelector(int position){

        viewPager.setCurrentItem(position);
        for (int i = 0; i < textViews.length; i++) {
            if (position == i){
                textViews[i].setSelected(true);
            }else {
                textViews[i].setSelected(false);
            }
        }
    }

}
